package com.shujia.day17.lambda;

import java.util.ArrayList;
import java.util.Iterator;

public class StaffOperator {
    public static void main(String[] args) {

        // 员工过滤年龄和工资案例。
        // 1.先创建员工对象 并将其添加到List集合中

        ArrayList<Staff> staffs = new ArrayList<>();

        staffs.add(new Staff("柏杨", 22, 16000));
        staffs.add(new Staff("张从文", 20, 15000));
        staffs.add(new Staff("唐彬", 21, 20000));
        staffs.add(new Staff("曹聪", 19, 21000));
        staffs.add(new Staff("赖成", 18, 25000));



        // 需求1.对年龄进行过滤出小于20岁的员工
        ArrayList<Staff> staff = filterAge(staffs);
        System.out.println(staff);

        // 需求2：过滤出薪资大于20000的员工

        ArrayList<Staff> staff1 = filterSalary(staffs);
        System.out.println(staff1);

    }


    public static ArrayList<Staff> filterAge(ArrayList<Staff> list){
        ArrayList<Staff> staff1 = new ArrayList<>();
        for (Staff staff : list) {
            if (staff.age < 20){
                staff1.add(staff);

            }
        }
        return staff1;
    }


    public static ArrayList<Staff> filterSalary(ArrayList<Staff> list){
        ArrayList<Staff> staff1 = new ArrayList<>();
        for (Staff staff : list) {
            if (staff.salary >= 20000){
                staff1.add(staff);

            }
        }
        return staff1;

    }


}
